<template>
  <div class="art-pub-container">
    <el-form ref="pubRef" label-width="100px" :model="addFrom" :rules="rules">
      <el-form-item label="文章标题" placeholder="请填写文章标题" prop="title">
        <el-input maxlength="30" v-model="addFrom.title"></el-input>
      </el-form-item>
      <el-form-item label="文章分类" prop="cate_id">
        <el-select placeholder="请选择分类" clearable v-model="addFrom.cate_id">
          <el-option
            v-for="item in cateList"
            :key="item.id"
            :label="item.cate_name"
            :value="item.id"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="文章内容"
        ><quill-editor v-model="addFrom.content"></quill-editor
      ></el-form-item>

      <el-form-item label="文章封面">
        <div class="cover-box">
          <img :src="addFrom.cover_img" alt="" class="cover-img" />
          <el-link type="primary" :underline="false">选择封面</el-link>
          <input type="file" ref="iptFile" accept="image/*" />
        </div>
      </el-form-item>
      <el-form-item>
        <el-button type="primary">发布文章</el-button>
        <el-button type="info">存为草稿</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import defaultImg from '@/assets/images/cover.jpg'
export default {
  name: 'ArtPub',
  data () {
    return {
      addFrom: {
        title: '',
        cate_id: '',
        content: '',
        state: '',
        cover_img: defaultImg
      },
      rules: {
        title: [
          { required: true, message: '请输入文章标题', trigger: 'blur' },
          {
            min: 1,
            max: 30,
            message: '文章标题的长度为1-30个字符',
            trigger: 'blur'
          }
        ],
        cate_id: [
          { required: true, message: '请选择文章分类', trigger: 'blur' }
        ]
      }
    }
  },
  computed: {
    ...mapState('article', ['cateList'])
  }
}
</script>

<style lang="less" scoped>
.art-pub-container {
  padding: 0 30px 20px 0px;
}

.el-select {
  width: 100%;
}

/deep/ .ql-snow .ql-color-picker .ql-picker-label svg,
/deep/ .ql-snow .ql-icon-picker .ql-picker-label svg {
  position: relative;
  top: -6px;
}

/deep/ .ql-snow .ql-picker-label::before {
  position: relative;
  top: -8px;
}

/deep/ .ql-editor {
  min-height: 300px;
}

.cover-img {
  object-fit: cover;
  width: 400px;
  height: 280px;
  margin-right: 10px;
}

.cover-box {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}
</style>
